#version 450

layout(location=0) in vec3 a_Pos;
layout(location=1) in vec2 a_Texcoord;

struct PerInstanceData {
    mat4 modelMat;
    uint arrayIndex;
};

layout(set=0, binding=0) uniform UBO {
    mat4 projMat;
    mat4 viewMat;
    PerInstanceData instances[8];
} ubo;

layout(location=0) out vec2 v_Texcoord;
layout(location=1) out float v_ArrayIndex;

void main() {
    gl_Position = ubo.projMat * ubo.viewMat * ubo.instances[gl_InstanceIndex].modelMat * vec4(a_Pos, 1.0);;
    v_Texcoord = a_Texcoord;
    v_ArrayIndex = ubo.instances[gl_InstanceIndex].arrayIndex;
}